<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateSysLogsTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        // create the table
        $table = $this->table('syslog');
        $table->addColumn(Column::string('module', 30)->setNullable()->setComment('模块名'))
            ->addColumn(Column::string('controller', 40)->setNullable()->setComment('控制器名'))
            ->addColumn(Column::string('action', 40)->setNullable()->setComment('方法名'))
            ->addColumn(Column::string('explain')->setNullable()->setComment('日志类型、注解'))
            ->addColumn(Column::text('message')->setNullable()->setComment('日志信息'))
            ->addColumn(Column::integer('user_id')->setNullable()->setComment('用户id'))
            ->addColumn(Column::string('user_ip', 40)->setNullable()->setComment('用户ip'))
            ->addColumn(Column::string('level', 10)->setDefault('info')->setComment('日志级别'))
            ->addColumn(Column::integer('create_time')->setComment('创建时间'))
            ->addColumn(Column::integer('update_time')->setComment('修改时间')->setNullable())
            ->addColumn(Column::integer('delete_time')->setComment('删除时间')->setNullable())
            ->create();
    }
}
